package rudolf.tools.network;

import java.io.IOException;
import java.io.InputStream;
import java.net.InetSocketAddress;
import java.net.MalformedURLException;
import java.net.Proxy;
import java.net.SocketAddress;
import java.net.Proxy.Type;
import java.net.URL;
import java.net.URLConnection;

public class NetworkTest {

	
	private static String URL[] = new String[]{
		"http://rudolfss13-spring-test.googlecode.com/svn/trunk", 
		"http://google.com" };
	private static int index = 0;
	private static SocketAddress proxyAddress = new InetSocketAddress("proxy", 3128);
	private static Proxy proxy = new Proxy(Type.HTTP, proxyAddress);
	
	public static void main(String[] args) throws IOException {
		URL url = new URL(URL[index]);
		URLConnection openConnection = null;
		if(proxy != null)
			openConnection = url.openConnection(proxy);
		else
			openConnection = url.openConnection();
			
		InputStream is = openConnection.getInputStream();
		byte buf[] = new byte[100];
		int l = 0;
		while((l = is.read(buf)) > 0)
			System.out.write(buf, 0, l);
	}
}
